/* GUI CONVERTED from rctxcal.i (converter v1.76) Fri Jun 14 04:11:36 2002 */
/* rctxcal.i - Recalculating Tax Details for Types 11/13                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 8.6E           CREATED: 08/03/00   BY: *L12D* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 03/16/01   BY: *N0XM* Mark Brown         */
/* Revision: 1.5      BY: Jean Miller     DATE: 03/22/01  ECO: *P008*         */
/* Revision: 1.6      BY: Katie Hilbert   DATE: 12/05/01  ECO: *P03C*         */
/* Revision: 1.7      BY: Patrick Rowan   DATE: 04/24/01  ECO: *P00G*         */
/* $Revision: 1.9 $   BY: Sandeep Parab   DATE: 06/04/02  ECO: *M1XH*         */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* RE-CALCULATING TAX DETAILS FOR TRANSACTION TYPES 11  */
/* AND 13 BY PROMPTING THE USER IF THE TAXES WERE       */
/* EDITED ELSE RE-CALCULATING THE TAXES UNCONDITIONALLY */

define variable l_so_tr_type like tx2d_tr_type initial "11" no-undo.
define variable l_tax_edited like mfc_logical               no-undo.
define variable l_calc_tax   like mfc_logical               no-undo.
define variable l_calc_tax1  like mfc_logical               no-undo.
define variable l_cpy_edit   like mfc_logical               no-undo.
define variable l_set_flg    like mfc_logical  extent 3     no-undo.

define temp-table wrk_so_calc no-undo
   fields wrk_so_nbr   like so_mstr.so_nbr
   fields wrk_so_quote like so_mstr.so_quote
   fields wrk_line     like l_line
   fields wrk_tr_type  like l_so_tr_type
   fields wrk_calc     like l_calc_tax
   index sonbr is primary wrk_so_nbr.

PROCEDURE p_taxcal:
/*--------------------------------------------------------------------
  Purpose:      Calculate Taxes
  Parameters:
  Notes:
 ----------------------------------------------------------------------*/

   define buffer wrk_so_calc    for wrk_so_calc.
   define buffer work_abs_mstr  for work_abs_mstr.
   define buffer sod_det        for sod_det.
   define buffer so_mstr        for so_mstr.
   define buffer tt_consign_rec for tt_consign_rec.
   define buffer buf_sod_det    for sod_det.

   run p_txcalc
      (input  "14",
       input  txcalcref,
       input  "*", /* ALL RELATED SO's */
       input  0,   /* ALL LINES        */
       input  no,  /* NO POSTING       */
       output result-status).

   assign
      l_set_flg   = yes
      l_calc_tax  = yes
      l_calc_tax1 = yes.

   for each wrk_so_calc
      exclusive-lock:
      delete wrk_so_calc.
   end. /* FOR EACH wrk_so_calc */

   for each work_abs_mstr
      no-lock,
      each  sod_det
      where sod_nbr  = abs_order
      and   sod_line = integer(abs_line)
      exclusive-lock,
      each  so_mstr
      where so_nbr   = sod_nbr
      exclusive-lock
   break by abs_order
         by abs_line:
/*GUI*/ if global-beam-me-up then undo, leave.


      /* IF CONSIGNMENT RECORDS EXIST FOR THE ORDER LINE */
      /* THEN DON'T CREATE TAX DETAIL BECAUSE THE LINE   */
      /* ACTUALLY HASN'T BEEN SHIPPED YET.               */

      if using_cust_consignment
      then do:

         l_consigned_line_item = no.
         {gprunmo.i &program = "socnsod1.p"
                    &module = "ACN"
                    &param = """(input  so_nbr,
                                 input  sod_line,
                                 output l_consigned_line_item,
                                 output consign_loc,
                                 output intrans_loc,
                                 output max_aging_days,
                                 output auto_replenish)"""}

         if l_consigned_line_item
         then do:
            create tt_consign_rec.
            assign tt_consign_order   = sod_nbr
                   tt_consign_line    = sod_line
                   tt_consign_qty_chg = sod_qty_chg.
                   sod_qty_chg        = 0.

         end. /* IF l_consigned_line_item */

      end. /* IF using_cust_consignment */

      if last-of(abs_order)
      then do:

         if  l_set_flg[1]
         and not can-find(first tx2d_det
                          where tx2d_ref     = so_nbr
                          and   tx2d_nbr     = so_quote
                          and   tx2d_tr_type = l_tr_type)
         then do:

            /* CHECK PREVIOUS DETAIL FOR EDITED VALUES */
            run p_txedtchk
               (input "11",
                input  so_nbr,
                input  so_quote,
                input  0,
                output l_tax_edited).

            if l_tax_edited
            then do:
               /* COPY EDITED TAX VALUES? */
               {pxmsg.i &MSGNUM=935 &ERRORLEVEL=2 &CONFIRM=l_cpy_edit}
               l_set_flg[1] = no.
            end. /* IF l_tax_edited */

         end. /* IF l_set_flg[1] AND NOT CAN-FIND */
         else do:

            /* CHECK PREVIOUS DETAIL FOR EDITED VALUES */
            run p_txedtchk
               (input  "13",
                input  so_nbr,
                input  so_quote,
                input  0,
                output l_tax_edited).

            if  l_tax_edited
            and l_set_flg[2]
            then do:

               /* EDITED PREVIOUS TAX VALUES- RECALCULATE ? */
               run p-msg
                  (input 2579,
                   input 2,
                   input "13",
                   output l_calc_tax1).

               l_set_flg[2] = no.
            end. /* IF l_tax_edited ... */

         end. /* ELSE DO */

         if l_calc_tax1
         or not l_tax_edited
         then do:
            run p_txcalc
               (input l_tr_type,
                input sod_nbr,
                input l_nbr,
                input l_line,
                input no,
                output result-status).
         end. /* IF l_calc_tax1 OR NOT l_tax_edited */

         if l_cpy_edit
         then do:
            {gprun.i ""txedtcpy.p""
               "(input  l_so_tr_type,
                 input  so_nbr,
                 input  so_quote,
                 input  l_tr_type,
                 input  so_nbr,
                 input  so_quote,
                 input  0)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         end. /* IF l_cpy_edit */

         /* CHECK PREVIOUS DETAIL FOR EDITED VALUES */
         run p_txedtchk
            (input  "11",
             input  so_nbr,
             input  so_quote,
             input  0,
             output l_tax_edited).

         if  l_tax_edited
         and l_set_flg[3]
         then do:

            /* EDITED PREVIOUS TAX VALUES - RECALCULATE ? */
            run p-msg
               (input 2579,
                input 2,
                input "11",
                output l_calc_tax).

            l_set_flg[3] = no.
         end. /* IF l_tax_edited AND l_set_flg[3] */

         find first wrk_so_calc
            where wrk_so_nbr = so_nbr
            exclusive-lock no-error.

         if not available wrk_so_calc
         then do:

            create wrk_so_calc.
            assign
               wrk_so_nbr   = so_nbr
               wrk_so_quote = so_quote
               wrk_line     = l_line
               wrk_tr_type  = l_so_tr_type
               wrk_calc     = (l_calc_tax
                               or not l_tax_edited).

         end. /* IF NOT AVAILABLE wrk_so_calc */

         /* RESET SOD_QTY_CHG BACK TO CONSIGNED QTY*/
         if using_cust_consignment
         then do:
            for each tt_consign_rec
               exclusive-lock:

               find first buf_sod_det
               where buf_sod_det.sod_nbr  = tt_consign_order
               and   buf_sod_det.sod_line = tt_consign_line
               exclusive-lock.

               buf_sod_det.sod_qty_chg = tt_consign_qty_chg.

               delete tt_consign_rec.
            end. /* FOR EACH tt_consign_rec */

         end. /* IF using_cust_consignment */

      end. /* IF LAST-OF (abs_order) */

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH WORK_ABS_MSTR */

END PROCEDURE. /* p_taxcal */

PROCEDURE p_wrk_so_calc:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
 ----------------------------------------------------------------------*/

   define buffer wrk_so_calc for wrk_so_calc.

   for each wrk_so_calc no-lock:
      if wrk_calc
         and can-find(first so_mstr
                      where so_nbr = wrk_so_nbr)
      then do:

         /* RE-CALCULATING TAX FOR TRANSACTION TYPE 11 */
         run p_txcalc
            (input wrk_tr_type,
             input wrk_so_nbr,
             input wrk_so_quote,
             input wrk_line,
             input no,
             output result-status).

      end. /* IF wrk_calc AND CAN-FIND(FIRST so_mstr) ... */

   end. /* FOR EACH wrk_so_calc */

END PROCEDURE . /* p_wrk_so_calc */

PROCEDURE p_txedtchk:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
 ----------------------------------------------------------------------*/
   define input  parameter l_trans_type like tr_type      no-undo.
   define input  parameter l_sonbr      like so_nbr       no-undo.
   define input  parameter l_soquote    like so_quote     no-undo.
   define input  parameter l_txline     like l_line       no-undo.
   define output parameter l_txedit     like l_tax_edited no-undo.

   {gprun.i ""txedtchk.p""
      "(input  l_trans_type,
        input  l_sonbr,
        input  l_soquote,
        input  l_txline,
        output l_txedit)"}
/*GUI*/ if global-beam-me-up then undo, leave.


END PROCEDURE. /* p_txedtchk */

PROCEDURE p_txcalc:
/*--------------------------------------------------------------------
  Purpose:      Calculate Taxes
  Parameters:
  Notes:
 ----------------------------------------------------------------------*/
   define input  parameter l_trns_type like tr_type      no-undo.
   define input  parameter l_sodnbr    like sod_nbr      no-undo.
   define input  parameter l_nbr1      like so_quote     no-undo.
   define input  parameter l_txline1   like l_line       no-undo.
   define input  parameter l_vq-post   like mfc_logical  no-undo.
   define output parameter l_result    like l_tax_edited no-undo.

   {gprun.i ""txcalc.p""
      "(input l_trns_type,
        input l_sodnbr,
        input l_nbr1,
        input l_txline1,
        input l_vq-post,
        output l_result)"}
/*GUI*/ if global-beam-me-up then undo, leave.


END PROCEDURE. /* p_txcalc */

PROCEDURE p-msg:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
 ----------------------------------------------------------------------*/
   define input  parameter l_msgnbr  as   integer     no-undo.
   define input  parameter l_msgstat as   integer     no-undo.
   define input  parameter l_chr1    as   character   no-undo.
   define output parameter l_ctax    like mfc_logical no-undo.

   {pxmsg.i &MSGNUM=l_msgnbr &ERRORLEVEL=l_msgstat
            &MSGARG1=l_chr1
            &CONFIRM=l_ctax
            &CONFIRM-TYPE='LOGICAL'}
END PROCEDURE.  /* p-msg */
